﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;

namespace CUWo.App.CustomControl.UserCenter
{

    public class TmpMessage : INotifyPropertyChanged
    {
        public int Id { get; set; }
        public string Title { get; set; }

        public string Content { get; set; }

        public DateTime InsertDateTime { get; set; }

        private bool _isRead;
        /// <summary>
        /// 已读标识
        /// </summary>
        public bool IsRead
        {
            get
            {
                return _isRead;
            }
            set
            {
                _isRead = value;
                NotifyPropertyChanged("IsRead");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName)
        {
            if (null != PropertyChanged)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }

    public partial class UCUserCenterMessage : UserControl
    {
        public ObservableCollection<TmpMessage> sources = new ObservableCollection<TmpMessage>();

        public UCUserCenterMessage()
        {
            InitializeComponent();
        }




        public void BindData()
        {
            this.LoadDataSource();
            this.llsMessage.ItemsSource = this.sources;
        }

        void LoadDataSource()
        {
            var m1 = new TmpMessage() { Id = 1, IsRead = false, Title = "短信送流量", Content = "", InsertDateTime = DateTime.Now.AddDays(-1) };
            this.sources.Add(m1);
            this.sources.Add(new TmpMessage() { Id = 2, IsRead = false, Title = "墨媒:政府将赔偿中铁建竞标体 赔偿金不超过2.7亿", Content = "", InsertDateTime = DateTime.Now.AddDays(-10) });
            this.sources.Add(new TmpMessage() { Id = 3, IsRead = false, Title = "日媒：中东铁路网建设热潮催生中日欧“争夺战”", Content = "", InsertDateTime = DateTime.Now.AddDays(-11) });
            this.sources.Add(new TmpMessage() { Id = 4, IsRead = false, Title = "韩观察员参加以中国为假想敌美日军演 被批不合适", Content = "", InsertDateTime = DateTime.Now.AddDays(-13) });
            this.sources.Add(new TmpMessage() { Id = 5, IsRead = true, Title = "安倍再向菲律宾撒钱 承诺提供200亿贷款用于防洪", Content = "", InsertDateTime = DateTime.Now.AddDays(-15) });
        }

        private void llsMessage_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            TmpMessage item = this.llsMessage.SelectedItem as TmpMessage;
            if (item != null)
            {
                //阅读后改变为已读的颜色，并且在离开页面时保存信息
                item.IsRead = true;
            }
        }


    }
}

